package demo1;
//介绍多态的优缺点
class Shape {
    public void draw() {
        System.out.println("实现画图形");
    }
}
class Cycle extends Shape {
    @Override
    public void draw() {
        System.out.println("⚪");
    }
}
class Rect extends Shape {
    @Override
    public void draw() {
        System.out.println("矩形");
    }
}
class Triangle extends Shape {
    @Override
    public void draw() {
        System.out.println("🔺");
    }
}

public class Test3 {
    public static void Drawmap(Shape shape) {
        shape.draw();
    }

    public static void main(String[] args) {
        //对比多态的优点
        Cycle cycle = new Cycle();
        Rect rect = new Rect();
        Triangle triangle = new Triangle();
        //非多态
        String[] string = {"cycle", "rect", "cycle", "rect", "ﬂower"};
        for(String s:string) {
            if(s.equals("cycle")) {
                Drawmap(cycle);
            } else if(s.equals("rect")) {
                Drawmap(rect);
            } else {
                Drawmap(triangle);
            }
        }
        System.out.println("--------------");
        //多态实现
        Shape[] shapes = {cycle,rect,cycle, rect,triangle};
        for(Shape s:shapes) {
            Drawmap(s);
        }

    }
    public static void main1(String[] args) {
        Cycle cycle = new Cycle();
        Rect rect = new Rect();
        Triangle triangle = new Triangle();

        Drawmap(cycle);
        Drawmap(rect);
        Drawmap(triangle);

    }

}
